'use strict';
import React    from 'react';
import Person   from '../entity/PersonBean';
import {UUID} from "../../lib.xjs/util/UUID";

const URL_ZHUHAI = "http://219.131.222.93:8001/rchc/ry";			// 正式

export default class HttpUtil{

    static getInstance() {
        if (typeof HttpUtil.instance === 'undefined') {
            HttpUtil.instance = new HttpUtil();
        }
        return HttpUtil.instance;
    }

    queryRY_BAK(callBack){
        setTimeout(this.doLoad.bind(this, callBack), 2000);
    };

    queryRY(callBack){
        setTimeout(
            () => {
                this.doLoad.bind(this, callBack);
            }, 2000);
    };

    doLoad(targetID, callBack){
        callBack(Person.QUERYING, '');

        fetch(URL_ZHUHAI, {
                method: 'POST',
                headers: {
                    'Accept': 'application/json',
                    'Content-Type': 'application/json; charset=utf-8',
                },
                timeout: 30 * 1000,
                body: JSON.stringify({
                    userid  : 't00010',
                    username: '许建森',
                    orgid   : 'cde25775-9118-4c42-b866-af161a7d418e',
                    mobile  : '13771825304',
                    sfzh    : targetID,
                    uuid    : UUID.getOne(),
                })
            })
            .then((response) => response.text())
            .then((jsonStr) => {
                console.log('查询返回：' + jsonStr);
                callBack(Person.RETURN_SUCCESS, jsonStr);
            })
            .catch((error) => {
                callBack(Person.RETURN_FAIL, '查询失败，' + error);
            });
    }
}
